<template>
  <div class="column-detail-page w-75 mx-auto">
    <div class="column-info row mb-4 border-bottom pb-4 align-items-center">
      <div class="col-3 text-center">
        <img :src="column.avatar.url" alt="" class="rounded-circle border">
      </div>
      <div class="col-9">
        <h4>{{ column.title }}</h4>
      </div>

    </div>
    <post-list :list="list"></post-list>

  </div>
</template>

<script lang="ts">
import {defineComponent,computed,onMounted} from "vue";
import {useRoute,useRouter} from "vue-router";
import {useStore} from "vuex";
import PostList from "@/components/PostList.vue";

export default defineComponent({
  components:{
    PostList
  },
  setup() {
    //它是一个函数，调用之后可以返回对应的对象
    const route = useRoute()
    const store = useStore()
    // const router = useRouter()
    // 获取到的和存在的数据类型不同，需要转换
    // 注意:不需要再转换成数字了 因为数据类型改变了
    const currenId = route.params.id
    onMounted(() => {
      // 专栏详情
      store.dispatch('fetchColumn',currenId)
      // 文章列表
      store.dispatch('fetchPosts',currenId)
    })
    const column = computed(() => store.getters.getColumnById(currenId))
    const list = computed(() => store.getters.getPostById(currenId))
    // router.push('/login')
    return {
      column,
      list
    }
  }
})
</script>

<style>

</style>
